package net.zigin.nhi.could.waste.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import net.zigin.commons.util.ReflectUtil;
import net.zigin.nhi.could.waste.dto.WarnWeightDto;
import net.zigin.nhi.could.waste.model.WarnWeight;
import net.zigin.nhi.could.waste.service.WarnWeightService;

import net.zigin.nhi.could.waste.vo.JsonForResult;
import net.zigin.nhi.could.waste.vo.WarnWeightVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * WarnWeight控制器类
 * @ClassName: WarnWeightController
 * @author mgw1986
 * @date 2021-9-20 19:47:13
 * @version V1.0
 */
@Api(tags = "超重预警管理")
@RestController
@RequestMapping("/warnWeight")
public class WarnWeightController extends BaseController {
	@Autowired
	private WarnWeightService warnWeightService;

	@PostMapping("/save")
	@ApiOperation("保存或编辑超重预警")
	@ApiImplicitParam(name = "warnWeightDto", value = "超重预警信息", required = true, dataType = "WarnWeightDto")
	public JsonForResult<String> save(@RequestBody WarnWeightDto warnWeightDto){
		String id = warnWeightService.saveOrUpdate(warnWeightDto);
		return JsonForResult.<String>builder().data(id).success(true).build();
	}

	@GetMapping("/getList")
	@ApiOperation("超重预警列表")
	public JsonForResult<List<WarnWeightVo>> getList(){
		List<WarnWeightVo> warnWeightVos = warnWeightService.getList();
		return JsonForResult.<List<WarnWeightVo>>builder().data(warnWeightVos).success(true).build();
	}

	@GetMapping("/getById/{id}")
	@ApiOperation("超时预警详情")
	@ApiImplicitParam(name = "id", value = "超重预警id", required = true, dataType = "String")
	public JsonForResult<WarnWeightVo> getById(@PathVariable String id){
		WarnWeight warnWeight = warnWeightService.selectByPrimaryKey(id);
		WarnWeightVo warnWeightVo = ReflectUtil.copyProperties(warnWeight, WarnWeightVo.class);
		return JsonForResult.<WarnWeightVo>builder().data(warnWeightVo).success(true).build();
	}

}
